import { makeAutoObservable } from "mobx";
interface Todo {
  id: number;
  todoName: string;
  isDone: boolean;
}
class TodoListStore {
  todoList = [
    {
      id: 1,
      todoName: "吃饭",
      isDone: false,
    },
    {
      id: 2,
      todoName: "睡觉",
      isDone: true,
    },
    {
      id: 3,
      todoName: "打豆豆",
      isDone: false,
    },
  ];
  get already() {
    const dd = this.todoList.filter((item) => item.isDone === true);
    return dd.length;
  }
  get total() {
    return this.todoList.length;
  }
  constructor() {
    makeAutoObservable(this);
  }
  //增加
  addTodo(value: string) {
    this.todoList.push({ id: Date.now(), todoName: value, isDone: false });
  }
  //切换选中
  checkedList(id: number) {
    const todo = this.todoList.find((item) => item.id === id) as Todo;
    todo.isDone = !todo.isDone;
  }
  //删除功能
  delList(id: number) {
    this.todoList = this.todoList.filter((item) => item.id !== id);
  }
  //全选与全不选
  alChecked(check: boolean) {
    this.todoList.forEach((item) => {
      item.isDone = check;
    });
  }
  //删除功能
  alDelList() {
    this.todoList = this.todoList.filter((item) => item.isDone === false);
  }
}

export default new TodoListStore();
